package com.tjetc.controller;

import com.tjetc.entity.Ads;
import com.tjetc.entity.Brands;
import com.tjetc.entity.LogisticsPartner;
import com.tjetc.service.BrandsService;
import com.tjetc.util.R;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 鞋品牌表(Brands)表控制层
 *
 * @author makejava
 * @since 2025-09-15 14:10:30
 */
@RestController
@RequestMapping("brands")
public class BrandsController {
    /**
     * 服务对象
     */
    @Resource
    private BrandsService brandsService;

    /**
     * 分页查询
     *
     * @param brands 筛选条件
      分页对象
     * @return 查询结果
     */
    @GetMapping("queryByPage")
    public R queryByPage(Brands brands, @RequestParam(defaultValue = "1")Integer pageNum,
                         @RequestParam(defaultValue = "10") Integer pageSize) {
        return R.ok(this.brandsService.queryByPage(brands, pageNum,pageSize));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Brands> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.brandsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param brands 实体
     * @return 新增结果
     */


    @PostMapping("/add")
    public R add(@RequestBody Brands brands) {
        return R.ok(brandsService.insert(brands));
    }

    /**
     * 编辑数据
     *
     * @param brands 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Brands> edit(Brands brands) {
        return ResponseEntity.ok(this.brandsService.update(brands));
    }

    @PostMapping("/update")
    public R updateById(@RequestBody Brands brands){
        this.brandsService.updateById(brands);
        return R.ok();
    }
    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("delete")
    public R deleteById(Long id) {
        return R.ok(this.brandsService.deleteById(id));
    }

    @GetMapping("queryAll")
    public R queryAll(){


        return R.ok(this.brandsService.queryAll());
    }
}

